#include "ustandard_sys.h"
#include "sqlite3.h"
int db_create(const char* name)
{
    int ret = 0;
    int retsql = 0;
    sqlite3* conn = NULL;
    char* err_msg = NULL;
    retsql = sqlite3_open(name, &conn);
    if(SQLITE_OK != retsql) {
        fprintf(stderr, "can not open db %s.\n", name);
        ret = -1;
        goto finish;
    }

    const char* str = "CREATE TABLE [acfun] ([tid] int PRIMARY KEY NOT NULL, [uid] varchar(20))";
    retsql = sqlite3_exec(conn, str, 0, 0, &err_msg);
    if(SQLITE_OK != retsql) {
        fprintf(stderr, "exec <%s> error : %s.\n", str, err_msg);
        ret = -1;
    }

    sqlite3_close(conn);
    conn = NULL;

finish:
    return ret;
}


int acfun_add_id(const char* name)
{
    int ret = 0;
    int retsql = 0;
    sqlite3* conn = NULL;
    char* err_msg = NULL;
    retsql = sqlite3_open(name, &conn);
    if(SQLITE_OK != retsql) {
        fprintf(stderr, "can not open db %s.\n", name);
        ret = -1;
        goto finish;
    }

    #define LEN     (1024)
    char str[LEN];
    int i;
    for(i=0; i<10000000; i++) {
        snprintf(str, LEN, "INSERT INTO [acfun] ([tid] , [uid] ) VALUES (%d, '%s')", 1, "");
        retsql = sqlite3_exec(conn, str, 0, 0, &err_msg);
        if(SQLITE_OK != retsql) {
            fprintf(stderr, "exec <%s> error : %s.\n", str, err_msg);
            ret = -1;
        }

        if(i%100 == 0) {
            printf(".");
        }
    }

    sqlite3_close(conn);
    conn = NULL;

finish:
    return ret;
}




int main()
{
    setbuf(stdout, NULL);
    if(0 != access("acfun.db", F_OK)) {
        db_create("acfun.db");
    }

    acfun_add_id("acfun.db");

    return 0;
}
